﻿using System;
using OpenTK.Graphics.OpenGL4;

namespace Painter3D.RenderSys
{
    /// <summary>
    /// 基本渲染管线
    /// </summary>
    class BasicRenderPiple : RenderPiple
    {
        public Transform skyBox;

        public BasicRenderPiple(Transform skyBox = null) : base()
        {
            this.skyBox = skyBox;
        }

        public override void RenderOut()
        {
            GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
            //三维不透明物体
            GL.Enable(EnableCap.DepthTest);
            RenderByCmareaWithMask(Camera.scenceMainCamera, RenderLayer.GetMask("default"));
            //三维透明物体
            GL.Enable(EnableCap.DepthTest);
            GL.Enable(EnableCap.Blend);
            GL.BlendFunc(BlendingFactor.SrcAlpha, BlendingFactor.OneMinusSrcAlpha);
            RenderByCmareaWithMask(Camera.scenceMainCamera, RenderLayer.GetMask("transparent"));
            
            //天空盒渲染
            GL.Enable(EnableCap.DepthTest);
            GL.DepthFunc(DepthFunction.Lequal);
            if (skyBox != null)
                RenderSkyBox(Camera.scenceMainCamera, skyBox);
            GL.DepthFunc(DepthFunction.Less);

            //指示符号
            GL.LineWidth(3.0f);
            GL.Clear(ClearBufferMask.DepthBufferBit);
            GL.Enable(EnableCap.DepthTest);
            GL.Enable(EnableCap.Blend);
            GL.BlendFunc(BlendingFactor.SrcAlpha, BlendingFactor.OneMinusSrcAlpha);
            RenderByCmareaWithMask(Camera.scenceMainCamera, RenderLayer.GetMask("symbol"));
            //指示文字
            GL.Disable(EnableCap.DepthTest);
            GL.Enable(EnableCap.Blend);
            GL.BlendFunc(BlendingFactor.SrcAlpha, BlendingFactor.OneMinusSrcAlpha);
            RenderByCmareaWithMask(Camera.scenceMainCamera, RenderLayer.GetMask("lable"));

            //UI渲染
            GL.Clear(ClearBufferMask.DepthBufferBit);
            GL.Enable(EnableCap.DepthTest);
            GL.Enable(EnableCap.Blend);
            GL.BlendFunc(BlendingFactor.SrcAlpha, BlendingFactor.OneMinusSrcAlpha);
            RenderByCmareaWithMask(Camera.uiMainCamera, RenderLayer.GetMask("ui"));
        }

    }
}
